package mydemo.springcloudalibaba.cousumer.order.controller;

import lombok.extern.slf4j.Slf4j;
import mydemo.springcloudalibaba.api.common.entity.CommonResult;
import mydemo.springcloudalibaba.api.common.entity.Payment;
import mydemo.springcloudalibaba.cousumer.order.service.PaymentOpenFiegnService;
import mydemo.springcloudalibaba.cousumer.order.service.PaymentOpenFiegnService_ForHystrix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
@Slf4j
public class PaymentController {
    @Autowired
    private PaymentOpenFiegnService paymentOpenFiegnService;
    @Autowired
    private PaymentOpenFiegnService_ForHystrix paymentOpenFiegnService_forHystrix;

    @RequestMapping("/get")
    public CommonResult get(Payment payment){
        return new CommonResult(200,"成功", paymentOpenFiegnService.getPaymentById(payment.getId()));
    }
    @RequestMapping("/timeout")
    public CommonResult timeout(Payment payment){
        return new CommonResult(200,"成功", paymentOpenFiegnService.timeout());
    }

    @RequestMapping("/getHystrix")
    public CommonResult getHystrix(Payment payment){
        return new CommonResult(200,"成功", paymentOpenFiegnService_forHystrix.getPaymentById_success(payment.getId()));
    }
    @RequestMapping("/errorHystrix")
    public CommonResult errorHystrix(Payment payment){
        return new CommonResult(200,"成功", paymentOpenFiegnService_forHystrix.getPaymentById_error(payment.getId()));
    }


}
